<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>login</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="./css/login.css" />
	<style>
	.aui-hide{
		  display: none !important;
	}
	</style>
</head>
<body>
	<div class="login_content_style">
		<div class="login_banner">
			<div class="login_back_icon" onclick="api.closeWin()">
				<img src="./image/login_back_icon.png" />
			</div>
			<img src="./image/login_banner.png" />
			<div class="login_top_bg"></div>
		</div>
		<div class="login_input_content">
			<div class="login_style_font">快捷登录</div>
			<div class="login_input_btn">
				<div class="login_phoen_style">
					<img src="./image/login_phone.png" />
					<input type="number" placeholder="请输入您的手机号" id="mobile" class="login_phone mobile">
				</div>
				<div class="login_phoen_style" id="yanz_code">
					<img src="./image/login_pwd.png" />
					<input type="text" placeholder="请输入验证码" id="mobile_captcha" class="login_code">
					<input type="button" class="login_btn_code" value="获取验证码" onclick="settime(this)" />
				</div>
				<div class="login_seat_kb"></div>
			</div>
		</div>
		<div class="login_btn" tapmode onclick="login()">
			<span>登录</span>
		</div>
		<div class="login_hx">
			<div class="login_other">第三方账户登录</div>
		</div>
		<div class="login_other_list">
			<img src="./image/logo_icon_03.png" onclick="loginPage()">
			<img src="./image/logo_icon_02.png" onclick="loginWx()">
			<img src="./image/logo_icon_01.png" onclick="loginQq()">
		</div>
		<div class="aceptBox" style="text-align:center;color:#bfbebe;margin-top:2rem;line-height: 18px;">
			<input checked class="aui-checkbox tongyizhuce" type="checkbox"> 同意
			<span style="color:#6871fb;" onclick="xieyi(52)">《用户协议》</span>
			<span style="color:#6871fb;" onclick="xieyi(53)">《隐私政策》</span>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/zepto.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/opensdk.js"></script>
<script type="text/javascript">
	var isinerval, times, smsVerify, pageParam;
	var countdown = 60;
	apiready = function() {
		api.parseTapmode();
		pageParam = api.pageParam;
		if (pageParam.data) {
			pageParam = pageParam.data;
		}
		smsVerify = api.require('smssdk');
	}

	function loginPage() {
   showToast('此版本不支持哦');
	}

	function loginWx() {
		if ($api.getStorage('wxisinstall') == 'true') {
			opensdk.wx.login(function(wxuser) {
				if (wxuser.wxnickname) {
					wxuser.logintype = 'wx';
					doLogin(wxuser);
				}
			})
		} else {
			showToast('未安装微信!');
		}

	}

	function loginQq() {
		opensdk.qq.installed(function(ret,err){
			if(ret.status){
				opensdk.qq.login(function(wxuser) {
					if (wxuser.nickname) {
						wxuser.logintype = 'qq';
						doLogin(wxuser);
					}
				})
			}else{
				showToast('未安装QQ!');
			}
		})
	}

	//发送验证码
	function settime(val) {
		var mobile = $("#mobile").val();
		if (mobile == "") {
			api.toast({
				msg: '请输入手机号!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		if (!(/^1[3456789]\d{9}$/.test(mobile))) {
			api.toast({
				msg: '手机号格式不正确，请重填!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		if (countdown == 0) {
			$(".login_btn_code").removeClass("active");
			val.removeAttribute("disabled");
			val.value = "获取验证码";
			countdown = 60;
			return;
		} else {
			$(".login_btn_code").addClass("active");
			val.setAttribute("disabled", true);
			val.value = "重新发送(" + countdown + ")";
			if (countdown == 60) {
				sendsmsfrommob(mobile);
			}
			countdown = parseInt(countdown) - 1;
		}
		setTimeout(function() {
			settime(val)
		}, 1000)
	}

	//发送短信
	function sendsmsfrommob(phone) {
		smsVerify.getTextCode({
			phoneNumber: phone,
			zone: '86'
		}, function(ret, err) {
			console.log(JSON.stringify(ret));
			console.log(JSON.stringify(err));
			if (err !== null && err !== undefined && err !== '') {
				showToast(err.msg);
			} else {
				api.toast({
					msg: '验证码已发送,请注意查收!',
					duration: 2000,
					location: 'middle'
				});
			}
		});
	}

	//验证短信
	function yzsms(phone, code) {
		smsVerify.commitCode({
			phoneNumber: phone,
			zone: '86',
			code: code,
		}, function(ret, err) {
			if (err !== null && err !== undefined && err !== '') {
				showToast(' 验证码不正确~');
			} else {
				showProgress('登录中');
				doLogin({
					phone: phone,
					logintype: 'mobile'
				});
			}
		});
	}

	function doLogin(param) {
		param.mobile = param.phone || '请绑定手机号';
		param.userid = param.openId || 10000;
		param.wxuserid = param.wxopenid || 99999;
		param.qquserid = param.qqopenid || 88888;
		param.logintype = param.logintype || 'moblile';
		postData(URL + 'Login/userLoginByMob', param, function(ret, err) {
			console.log(JSON.stringify(ret));
			console.log(JSON.stringify(err));
			hideProgress();
			if (ret) {
				console.log(JSON.stringify(ret));
				if (ret.code == 1 && ret.logintype == 2) {
					openWinto('bind_phone', 'widget://html/my/bind_phone', {
						param: param
					});
					return;
				}
				if (ret.code == 1) {
					$api.setStorage('taobao_user', {
						'mobile': ret.data.mobile,
						'level_name': ret.data.level_name,
						'islogin': true,
						'yjrate': ret.data.yjrate,
						'xjyjrate': ret.data.xjyjrate,
						'id': ret.data.userid,
						'relation_id': ret.data.relation_id
					});
					var jsfun = 'location.reload();';
					if (pageParam.fromwin == 'root') {
						api.execScript({
							name: 'root',
							frameName: 'my_win',
							script: jsfun
						});
					} else {
						api.execScript({
							name: pageParam.fromwin,
							script: jsfun
						});
					}
					api.closeWin();
					showToast(TipInfo.data_login_succuss);
				} else {
					showToast(TipInfo.data_login_fail);
				}
			} else {
				showToast(TipInfo.data_busy);
			}
		});
	}
	//登录
	function login() {
		var mobile = $("#mobile").val();
		var mobile_captcha = $("#mobile_captcha").val();
		var invitation_code = "";
		if (mobile == "") {
			api.toast({
				msg: '请输入手机号!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		if (mobile_captcha == "") {
			api.toast({
				msg: '请输入验证码!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		if (!(/^1[3456789]\d{9}$/.test(mobile))) {
			api.toast({
				msg: '手机号格式不正确，请重填!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		if (!$('.tongyizhuce').prop('checked')) {
			api.toast({
				msg: '请同意注册协议!',
				duration: 2000,
				location: 'middle'
			});
			return false;
		}
		yzsms(mobile, mobile_captcha);
	}
</script>

</html>
